<script lang="ts" setup>
import { ref } from 'vue'
import { Menu as IconMenu, Location, Fold, Expand } from '@element-plus/icons-vue'
import { defineEmits } from 'vue'

// 声明触发的事件类型
const emits = defineEmits(['messageEvent'])

const isCollapse = ref<boolean>(false)

const openOrClose = () => {
  isCollapse.value = !isCollapse.value
  emits('messageEvent', isCollapse.value); // 触发事件并传递数据
}

const handleOpen = (key: string, keyPath: string[]) => {
  console.log(key, keyPath)
}
const handleClose = (key: string, keyPath: string[]) => {
  console.log(key, keyPath)
}
</script>

<template>
  <div class="openOrClose" @click="openOrClose">
    <Fold class="fold"/>
    <!-- <Expand class="expand"/> -->
  </div>

  <el-menu
    default-active="2"
    class="el-menu-vertical-demo"
    :collapse="isCollapse"
    @open="handleOpen"
    @close="handleClose"
  >
    <el-sub-menu index="1">
      <template #title>
        <el-icon><location /></el-icon>
        <span>Navigator One</span>
      </template>
      <el-menu-item-group>
        <template #title><span>Group One</span></template>
        <el-menu-item index="1-1">item one</el-menu-item>
        <el-menu-item index="1-2">item two</el-menu-item>
      </el-menu-item-group>
      <el-menu-item-group title="Group Two">
        <el-menu-item index="1-3">item three</el-menu-item>
      </el-menu-item-group>
      <el-sub-menu index="1-4">
        <template #title><span>item four</span></template>
        <el-menu-item index="1-4-1">item one</el-menu-item>
      </el-sub-menu>
    </el-sub-menu>

  </el-menu>
</template>

<style>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}

.openOrClose {
  background-color: aqua;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.fold,
.expand {
  width: 30px;
  height: 30px;
}
</style>
